package com.neuedu.his.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.neuedu.his.po.Department;
import com.neuedu.his.po.Fmeditem;
import com.neuedu.his.service.DepartmentService;
import com.neuedu.his.service.FmeditemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/fmeditem")
public class FmeditemController {

    @Autowired
    FmeditemService service;
    @Autowired
    DepartmentService departmentService;

    @RequestMapping("/getbyrecordtype")
    public List<Map<String,Object>> getbyrecordtype(@RequestParam Integer id){
        QueryWrapper<Fmeditem> qw=new QueryWrapper<>();
        qw.eq("recordtype",id);
        List<Fmeditem> fmeditems=service.list(qw);

        List<Map<String,Object>> result=new ArrayList<>();
        for(Fmeditem item:fmeditems){
            Map<String,Object> map=new HashMap<>();
            map.put("id",item.getId());
            map.put("itemname",item.getItemname());

            Department department=departmentService.getById(item.getDeptid());
            map.put("deptname",department!=null?department.getDeptname():"Unknown");
            result.add(map);
        }
        return result;
    }

}
